package com.administrator.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.administrator.service.ProductService;
import com.entity.Product;



/**
 * Servlet implementation class UserAddServlet
 */
@WebServlet("/register")
public class UserAddServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UserAddServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html; charset=UTF-8");
		
		String username = request.getParameter("username");
        String password = request.getParameter("password");
        String repassword = request.getParameter("repassword");
		 if(username!=null&&password!=null&&repassword!=null)
	        {
	            if(!username.equals(""))
	            {
	               if(password.equals(repassword))
	              {
	                response.getWriter().write("注册成功！");
	                response.setHeader("refresh", "3;URL=b_login.jsp");
	              }
	              else
	              {
	                
	                response.getWriter().write("两次密码输入不同，请检查后重新输入！");
	                response.setHeader("refresh", "3;URL=register.jsp");
	              }
	            }
	            else
	            {
	                response.getWriter().write("用户名不能为空!");
	                response.setHeader("refresh", "3;URL=register.jsp");
	            }
	         }
		
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
